package com.young.client;

import com.alibaba.fastjson.JSON;
import com.young.dao.AdminDao;
import com.young.entity.Admin;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.log4j.Logger;

import java.io.InputStream;
import java.util.List;

/**
 * @description：
 * @author: yangyahui01
 * @date: 9/25/24 11:46 AM
 */
public class ClientApp {

    static final Logger logger = Logger.getLogger(ClientApp.class);

    public static void main(String[] args) throws Exception {
        demo();
    }

    public static void demo() throws Exception{
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");

        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        SqlSession sqlSession = sqlSessionFactory.openSession();

        AdminDao dao = sqlSession.getMapper(AdminDao.class);
        List<Admin> admins = dao.getAll();
        logger.info(JSON.toJSONString(admins));
    }
}
